package com.wngbms._06;

import okhttp3.*;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

public class OkhttpDemo {

    public static void main(String[] args) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();

        Request request = new Request
                .Builder()
                .url("http://localhost:8090")
                .get().build();

        Call call = okHttpClient.newCall(request);
//        m1(call);
        Response response = call.execute();
        System.out.println(response.body().string());

        response.close();

    }

    private static void m1(Call call) {
        System.out.println(call + "\t" + Thread.currentThread().getName());
        call.enqueue(new Callback() {
            @Override
            public void onFailure(@NotNull Call call, @NotNull IOException e) {
                System.out.println(call);
            }

            @Override
            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                System.out.println(call + "\t" + Thread.currentThread().getName());
                System.out.println(response.body().string());
            }
        });
    }

}
